
//
//  OptionHeaderView.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/26.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "OptionHeaderView.h"
#define STANCE 5

@implementation OptionHeaderView

- (instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self createUI];
    }
    return self;
}

- (void)loadWithData:(OptionModel *)mol{

    _commentLabel.text = mol.ztnr;
    _timeLabel.text    = mol.input_time;
    _replyCount.text   = mol.replycount;
    
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:_commentLabel.text];;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:5];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, _commentLabel.text.length)];
    
    _commentLabel.attributedText = attributedString;
    //调节高度
    CGSize sizes = CGSizeMake(SIZEWIDTH - ScaleSize(42)*2, 0);
    
    CGSize labelSize = [_commentLabel sizeThatFits:sizes];
    
    
    _commentLabel.frame = CGRectMake(ScaleSize(42), ScaleSize(69), SIZEWIDTH- ScaleSize(42)*2, labelSize.height);
    
    
    _uname.frame = CGRectMake(ScaleSize(42), CGRectGetMaxY(_commentLabel.frame)+ScaleSize(39), 250, 25);
    //     [_uname sizeToFit];
    _timeLabel.frame = CGRectMake(CGRectGetMaxX(_uname.frame)+ScaleSize(51), CGRectGetMaxY(_commentLabel.frame)+ScaleSize(39), 150, 25);
    //    [_timeLabel sizeToFit];
    
    _replyCount.frame = CGRectMake(SIZEWIDTH-23, CGRectGetMaxY(_commentLabel.frame)+ScaleSize(39), 30, 25);
    _icon.frame =CGRectMake(SIZEWIDTH-23-ScaleSize(21)-14, CGRectGetMaxY(_commentLabel.frame)+ScaleSize(39)+4, ScaleSize(48), ScaleSize(48));
    
    _xianImage.frame = CGRectMake(0, CGRectGetMaxY(_uname.frame)+ScaleSize(50), SIZEWIDTH, 5);
    
    [self setFrame:CGRectMake(0, 0, self.frame.size.width, CGRectGetMaxY(_uname.frame)+ScaleSize(50))];
    self.myBlock(self.frame.size.height);
    
    _uname.text = [NSString stringWithFormat:@"%@     %@",mol.uname,mol.input_time];
    _uname.font =  NormalFont(36);
    _uname.keyWord = [NSString stringWithFormat:@"%@",mol.input_time];
    
    _uname.keyWordColor = Color999999;
    _uname.keyWordFont = NormalFont(33);

}


-(void)createUI{
    _commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, SIZEWIDTH-20, 0)];
    _commentLabel.numberOfLines = 0;
    
    //    [_commentLabel sizeToFit];
    
    
    
    
    _commentLabel.textColor = Color333333;
    _commentLabel.font = NormalFont(42);
    
    _uname = [[MMLabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(_commentLabel.frame)+STANCE, 120, 25)];
    
    _uname.textColor = color666666;
    
    
    _replyCount = [[UILabel alloc]initWithFrame:CGRectMake(SIZEWIDTH-20, CGRectGetMaxY(_commentLabel.frame)+STANCE+3, 30, 25)];
    _replyCount.textColor = Color999999;
    
    _replyCount.font = NormalFont(33);
    _icon = [[UIImageView alloc]initWithFrame:CGRectMake(SIZEWIDTH-42, CGRectGetMaxY(_commentLabel.frame)+STANCE+5, ScaleSize(48), ScaleSize(48))];
    _icon.image = [UIImage imageNamed:@"讨论icon.png"];
    
    [self addSubview:_icon];
    [self addSubview:_replyCount];
    [self addSubview:_uname];
    [self addSubview:_commentLabel];
    _xianImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_uname.frame)+20, SIZEWIDTH, ScaleSize(15))];
    _xianImage.image = [UIImage imageNamed:@"讨论详情分割线"];
    _xianImage.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:_xianImage];
    
    
}
@end
